package StudentManager;

import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.Callable;

public class DemoCar {
    public static void main(String[] args) {
        ArrayList<Car> array = new ArrayList<Car>();
        Scanner sc = new Scanner(System.in);
        Car c1 = new Car("奔驰s450", 45, "黑色", 20);
        Car c2 = new Car("宝马520", 38, "白色", 30);
        array.add(c1);
        array.add(c2);
        while (true) {
            System.out.println("========库存管理========");
            System.out.println("1:查看库存清单");
            System.out.println("2:修改库存清单");
            System.out.println("3:退出");
            System.out.println("请输入你要执行的操作序号");
            int num = sc.nextInt();
            switch (num) {
                case 1:
                    show(array);
                    break;
                case 2:
                    xiugai(array);
                    break;
                case 3:
                    System.out.println("谢谢使用");
                    System.exit(0);
            }
        }


    }

    public static void show(ArrayList<Car> array) {
        System.out.println("========商城库存清单========");
        System.out.println("品牌\t\t价格\t颜色\t库存");
        int k = 0;
        int k1 = 0;
        for (int i = 0; i < array.size(); i++) {
            Car c = array.get(i);
            System.out.println(c.getBrand() +"\t"+ c.getPrice() + "\t"+c.getColor()
                    + "\t"+c.getKucun());
            k += c.getKucun() * c.getPrice();
            k1 += c.getKucun();
        }
        System.out.println("=========================");
        System.out.println("总库存：" + k1);
        System.out.println("总库存金额" + k);
    }

    public static void xiugai(ArrayList<Car> array) {
        System.out.println("请输入你要修改的品牌");
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int idex = -1;
        for (int i = 0; i < array.size(); i++) {
            Car c = array.get(i);
            if (c.getBrand().equals(s)) {
                idex = i;
                break;
            }
        }
        if(idex==-1){
            System.out.println("你输入的品牌有误");
        }else{
            System.out.println("请输入新的的库存数量");
            int a=sc.nextInt();
            array.get(idex).setKucun(a);
            System.out.println("修改成功");
        }


    }
}